package com.crawling.controller;

import com.crawling.service.CrawlingBeginService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * 控制器
 *
 * @author lr
 */
@Controller
@RequestMapping("/crawling")
@Slf4j
public class CrawlingBeginController {

    @Autowired
    CrawlingBeginService crawlingBeginService;

    /**
     * 开始爬取
     */
    @RequestMapping(value = "/start//{key1}/{key2}")
    @ResponseBody
    public Object start(@PathVariable String key1, @PathVariable String key2) {
        log.info("开始爬取 time:{}", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        return crawlingBeginService.start(key1, key2);

    }

    /**
     * 开始爬取
     */
    @RequestMapping(value = "one")
    @ResponseBody
    public Object one(String url) {
        log.info("开始爬取 time:{}", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
        return crawlingBeginService.one(url);

    }

}
